<template>
	<view>
		<view class="content">
			<textarea v-model="form.content" focus="true" maxlength="-1" placeholder="和校友说点什么..." placeholder-style="color: #C2C7CC" />
		</view>
		<view class="bot-btn">
			<image src="../../static/fdt_img.png" mode="" @click="upImg()"></image>
			<view class="btn-box">
				<view class="cacel" @click="cancelSend()">取消</view>
				<view class="send" @click="sendDynamic()">发布</view>
			</view>
		</view>
		<view class="pic-center">
			<image v-for="(item,index) in pic" :key="index" :src="item" mode=""></image>
		</view>
		<image-picker :hide="true" ref="imgPicker" :count="9" @success="upSuccess"></image-picker>
	</view>
</template>

<script>
	import ImagePicker from '@/components/image-picker.vue'
	export default {
		components: {
			ImagePicker
		},
		data() {
			return {
				form:{
					content:'',
					school_id:'',
					pid:'',
					pic:[]
				},
				pic:[]
			}
		},
		onLoad(e) {
			this.form.school_id = e.school_id
			this.form.pid = e.pid
		},
		methods: {
			async sendDynamic(){
				const res = await this.get('/index/User/add_school_student_listen', this.form)
				if(res.code == 200){
					uni.showToast({
						title:'发布成功',
						duration:800,
						success: () => {
							setTimeout(()=>{
								uni.redirectTo({
									url:'./alumni_circle?school_id='+this.form.school_id
								})
							},800)
						}
					})
				}
			},
			cancelSend() {
				uni.showModal({
					title: '温馨提示',
					content: '确定取消发布此动态吗？',
					success: (res) => {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.showToast({
								title:'取消发布',
								duration:600,
								icon:'none',
								success: () => {
									setTimeout(()=>{
										uni.navigateBack({
											delta:1
										})
										// uni.redirectTo({
										// 	url:'./alumni_circle?school_id='+this.form.school_id
										// })
									},600)
								}
							})
						}
					}
				})
			},
			upImg(){
				this.$refs.imgPicker.ChooseImage()
			},
			upSuccess(res) {
				this.pic.push(res.file)
				let picRep=this.pic.toString()
				this.form.pic=picRep.replace(/,/g,";")
				var a=this.form.pic
				console.log(JSON.stringify(a))
				console.log("a:",a)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		padding: 20upx 24upx;
		position: relative;
		textarea{
			width: 637upx;
			height: 370upx;
			font-size: 28upx;
			line-height: 44upx;
			letter-spacing: 1upx;
			border: 2upx solid #E1E3E6;
			padding: 22upx 30upx 60upx 30upx;
		}
	}
	.bot-btn{
		display: flex;
		align-items: center;
		padding: 0 35upx;
		position: absolute;
		top: 415upx;
		left: 0;
		image{
			width: 48upx;
			height: 48upx;
		}
		.btn-box{
			display: flex;
			font-size: 28upx;
			margin-left: 420upx;
			.cacel{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 94upx;
				height: 52upx;
				color: #101010;
				border-radius: 10upx;
				border: 2upx solid #C2C7CC;
			}
			.send{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 94upx;
				height: 52upx;
				color: #FFFFFF;
				margin-left: 24upx;
				background: #3291F8;
				border-radius: 10upx;
			}
		}
	}
	.pic-center{
		display: flex;
		flex-flow: wrap;
		padding: 0 24upx;
		image{
			width: 230upx;
			height: 230upx;
			margin-bottom: 6upx;
		}
		image:nth-child(2),image:nth-child(5),image:nth-child(8){
			margin: 0 6upx;
		}
	}
</style>
